<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>智慧家庭套餐定制</title>
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #3498db;
            --success-color: #27ae60;
            --border-color: #e0e0e0;
        }

        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background: #f5f7fa;
            padding: 20px;
            padding-bottom: 100px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .section {
            background: white;
            border-radius: 10px;
            padding: 25px;
            margin-bottom: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        .section-title {
            color: var(--primary-color);
            border-bottom: 2px solid var(--border-color);
            padding-bottom: 10px;
            margin-bottom: 20px;
            font-size: 1.2em;
        }

        .option-group {
            display: grid;
            gap: 15px;
        }

        .option-item {
            display: flex;
            align-items: flex-start;
            padding: 15px;
            border: 2px solid var(--border-color);
            border-radius: 8px;
            transition: all 0.3s;
            position: relative;
            cursor: pointer;
        }

        .option-item.required {
            background: #f8f9fa;
        }

        .option-item.selected {
            border-color: var(--secondary-color);
            background: #f0f8ff;
        }

        input[type="checkbox"], 
        input[type="radio"] {
            width: 18px;
            height: 18px;
            margin: 5px 15px 0 0;
            cursor: pointer;
        }

        .item-content {
            flex: 1;
        }

        .item-title {
            font-weight: bold;
            margin-bottom: 8px;
            color: var(--primary-color);
        }

        .item-detail {
            color: #666;
            font-size: 0.9em;
            line-height: 1.6;
        }

        .price-tag {
            margin-left: 20px;
            min-width: 120px;
            text-align: right;
        }

        .price-monthly {
            color: var(--success-color);
            font-weight: bold;
        }

        .price-total {
            color: #999;
            font-size: 0.8em;
        }

        /* 汇总面板样式 */
        .summary-container {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            background: white;
            box-shadow: 0 -5px 15px rgba(0,0,0,0.1);
            z-index: 100;
            transition: all 0.3s;
        }

        .summary-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px 20px;
            background: var(--primary-color);
            color: white;
            cursor: pointer;
        }

        .summary-content {
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease-out;
            padding: 0 20px;
        }

        .summary-content.expanded {
            max-height: 400px;
            padding: 20px;
            overflow-y: auto;
        }

        .summary-item {
            margin: 15px 0;
            padding-bottom: 15px;
            border-bottom: 1px solid var(--border-color);
        }

        .total-price {
            font-size: 1.5em;
            color: var(--primary-color);
            font-weight: bold;
            text-align: right;
            margin-top: 20px;
        }

        .sub-items {
            padding-left: 15px;
            color: #666;
            margin-top: 8px;
            font-size: 0.9em;
        }

        .toggle-icon {
            transition: transform 0.3s;
        }

        .toggle-icon.expanded {
            transform: rotate(180deg);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .option-group {
                grid-template-columns: 1fr;
            }
            
            .price-tag {
                min-width: 100px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 必选套餐 -->
        <div class="section">
            <h2 class="section-title">默认套餐</h2>
            <div class="option-group" id="requiredOptions"></div>
        </div>

        <!-- 终端大礼包 -->
        <div class="section">
            <h2 class="section-title">终端大礼包</h2>
            <div class="option-group" id="terminalOptions"></div>
        </div>

        <!-- 共享大礼包 -->
        <div class="section">
            <h2 class="section-title">全家共享大礼包</h2>
            <div class="option-group" id="sharedOptions"></div>
        </div>
    </div>

    <!-- 可折叠汇总面板 -->
    <div class="summary-container">
        <div class="summary-header" onclick="toggleSummary()">
            <span>已选套餐 (点击展开/折叠)</span>
            <span class="toggle-icon">▼</span>
        </div>
        <div class="summary-content" id="summaryContent">
            <div id="summaryItems"></div>
            <div class="total-price">总费用：¥0</div>
        </div>
    </div>

<script>
// 套餐数据配置
const packages = {
    required: [
        {
            id: 'base',
            name: '基础套餐',
            detail: [
                "语音：300分钟",
                "流量：100G（80G省内）"
            ],
            price: 0
        },
        {
            id: 'broadband',
            name: '宽带大礼包',
            detail: [
                "1000M宽带",
                "电视高清机顶盒（15元/月×36个月，总计540元）",
                "千兆路由器（10元/月×36个月，总计360元）"
            ],
            price: 0
        },
        {
            id: 'benefit',
            name: '权益大礼包',
            detail: [
                "139邮箱+移动云盘",
                "视频会员包5选1",
                "15GB定向流量"
            ],
            price: 0
        }
    ],
    terminal: [
        {
            id: 'terminal1',
            name: '5G金币活动-79元档',
            detail: "承诺保底79元，20GB+预存600元话费返600元",
            price: 600
        },
        {
            id: 'terminal2',
            name: '5G金币活动-129元档',
            detail: "承诺保底129元，25GB+预存1000元话费返1000元",
            price: 1000
        },
        {
            id: 'terminal3',
            name: '5G金币活动-159元档',
            detail: "承诺保底159元，25GB+预存1400元话费返1400元",
            price: 1400
        },
        {
            id: 'terminal4',
            name: '家庭安防',
            detail: "家庭安防，每月12元*36个月",
            price: 432
        },
        {
            id: 'terminal5',
            name: '教育台灯',
            detail: "智能台灯，每月15元*36个月",
            price: 540
        }
    ],
    shared: [
        {
            id: 'health1',
            name: '爱家人-血压仪',
            detail: "每月10元×24个月（总计240元）",
            price: 10*24
        },
        {
            id: 'health2',
            name: '爱家人-体脂秤',
            detail: "每月10元×24个月（总计240元）",
            price: 10*24
        },
        {
            id: 'flow1',
            name: '功能副卡',
            detail: "流量卡：每月50GB，10元×60个月（总计600元）",
            price: 10*60
        },
        {
            id: 'flow2',
            name: '生活福利包-短视频流量包',
            detail: "100GB抖音快手流量，10元/月",
            price: 10*12
        },
        {
            id: 'service',
            name: '生活福利包-车主权益包',
            detail: "加油、洗车、停车、充电等每月N选1+10GB区域流量，每月19.9元*12个月（总计480元）",
            price: 480
        }
    ]
};

// 初始化套餐选择
function initOptions() {
    renderGroup('required', 'requiredOptions', true);
    renderGroup('terminal', 'terminalOptions', false, 'radio');
    renderGroup('shared', 'sharedOptions', false, 'checkbox');
    
    // 默认选中第一个终端选项
    document.querySelector('#terminalOptions input').checked = true;
}

// 渲染选项组
function renderGroup(type, containerId, isRequired, inputType = 'checkbox') {
    const container = document.getElementById(containerId);
    container.innerHTML = packages[type].map(item => `
        <label class="option-item ${isRequired ? 'required' : ''}">
            <input type="${inputType}" 
                   ${isRequired ? 'checked disabled' : ''}
                   name="${type}Group"
                   data-id="${item.id}"
                   data-price="${item.price}"
                   onchange="updateSummary()">
            <div class="item-content">
                <div class="item-title">${item.name}</div>
                <div class="item-detail">${
                    Array.isArray(item.detail) ? 
                    item.detail.join('<br>') : item.detail
                }</div>
            </div>
            ${item.price > 0 ? `
            <div class="price-tag">
                <div class="price-monthly">¥${item.price}</div>
                <div class="price-total">合约总价</div>
            </div>` : ''}
        </label>
    `).join('');
}

// 更新汇总信息
function updateSummary() {
    const selectedItems = [];
    let total = 0;

    // 收集必选套餐
    packages.required.forEach(item => {
        selectedItems.push(createSummaryItem(item));
        total += item.price;
    });

    // 收集终端优惠
    const terminal = document.querySelector('#terminalOptions input:checked');
    if(terminal) {
        const item = packages.terminal.find(p => p.id === terminal.dataset.id);
        selectedItems.push(createSummaryItem(item));
        total += item.price;
    }

    // 收集共享礼包
    document.querySelectorAll('#sharedOptions input:checked').forEach(input => {
        const item = packages.shared.find(p => p.id === input.dataset.id);
        selectedItems.push(createSummaryItem(item));
        total += item.price;
    });

    // 更新显示
    document.getElementById('summaryItems').innerHTML = selectedItems.join('');
    document.querySelector('.total-price').textContent = `总费用：¥${total.toFixed(1)}`;
}

// 创建汇总条目
function createSummaryItem(item) {
    return `
        <div class="summary-item">
            <div class="item-title">${item.name}</div>
            ${item.detail ? `
            <div class="sub-items">
                ${Array.isArray(item.detail) ? 
                    item.detail.join('<br>') : item.detail}
            </div>` : ''}
            ${item.price > 0 ? `
            <div style="text-align: right; margin-top: 5px;">
                <span class="price-monthly">¥${item.price}</span>
            </div>` : ''}
        </div>
    `;
}

// 切换汇总面板
function toggleSummary() {
    const content = document.getElementById('summaryContent');
    const icon = document.querySelector('.toggle-icon');
    content.classList.toggle('expanded');
    icon.classList.toggle('expanded');
}

// 初始化页面
initOptions();
updateSummary();
</script>
</body>
</html>